package com.example.cushion.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.cushion.R;
import com.example.cushion.bean.MyMenuItem;

import org.itzheng.and.baseutils.common.ArrayUtils;
import org.itzheng.and.baseutils.ui.UIUtils;
import org.itzheng.and.recyclerview.adapter.BaseRecyclerAdapter;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Title:<br>
 * Description: <br>
 *
 * @email ItZheng@ZoHo.com
 * Created by itzheng on 2018-3-8.
 */
public class SettingAdapter extends BaseRecyclerAdapter<SettingAdapter.ViewHolder> {
    List<MyMenuItem> mItems;

    public SettingAdapter(List<MyMenuItem> items) {
        mItems = items;
    }

    @Override
    public View onCreateView(ViewGroup parent, int viewType) {
        return UIUtils.inflateAdapterView(R.layout.adapter_item_setting, parent);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(onCreateView(parent, viewType));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        final MyMenuItem item = mItems.get(position);
        holder.tvTitle.setText(item.name);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (item.clazz != null)
                    UIUtils.startActivity(item.clazz);
            }
        });
    }

    @Override
    public int getItemCount() {
        return ArrayUtils.size(mItems);
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tvTitle)
        TextView tvTitle;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
//            tvTextView = (TextView) itemView;
        }
    }
}
